//
//  OrderDetailView.m
//  OrderFood
//
//  Created by xiaofang wang on 2018/10/25.
//  Copyright © 2018年 zhiyuan. All rights reserved.
//

#import "OrderDetailView.h"

@implementation OrderDetailView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setUI];
    }
    return self;
}
-(void)setUI{
    
    self.quImg = [[UIImageView alloc] initWithFrame:CGRectMake(15, 30, 30, 30)];
    self.quImg.image = IMAGE(NSLocalizedString(@"qucan", nil));
    [self addSubview:self.quImg];
    
    self.qh_storeLb = [[UILabel alloc] initWithFrame:CGRectMake(self.quImg.mh_right+25, self.quImg.mh_top-5, SCREEN_WIDTH - 60-self.quImg.mh_width, 25)];
    self.qh_storeLb.font = FONT(15);
//    self.qh_storeLb.backgroundColor = [UIColor redColor];
//    self.qh_storeLb.text = @"肯德基（火车站店)";
    [self addSubview:self.qh_storeLb];
    
    self.qh_addressLb = [[UILabel alloc] initWithFrame:CGRectMake(self.qh_storeLb.mh_left, self.qh_storeLb.mh_bottom, SCREEN_WIDTH - 60-self.quImg.mh_width, 20)];
    self.qh_addressLb.font = FONT(14);
    self.qh_addressLb.textColor = themeTextColor;
//    self.qh_addressLb.text = @"杭州火车东站售票厅西侧";
    [self addSubview:self.qh_addressLb];
    
    
    self.songImg = [[UIImageView alloc] initWithFrame:CGRectMake(15, self.quImg.mh_bottom+70, 30, 30)];
    self.songImg.image = IMAGE(NSLocalizedString(@"songcan", nil));
    [self addSubview:self.songImg];
    
    self.sh_addressLb = [[UILabel alloc] initWithFrame:CGRectMake(self.songImg.mh_right+25, self.songImg.mh_top-5, SCREEN_WIDTH - 60-self.songImg.mh_width, 25)];
    self.sh_addressLb.font = FONT(15);
//    self.sh_addressLb.text = @"西湖写字楼1栋158";
    [self addSubview:self.sh_addressLb];
    
    self.sh_contactLb = [[UILabel alloc] initWithFrame:CGRectMake(self.sh_addressLb.mh_left, self.sh_addressLb.mh_bottom, SCREEN_WIDTH - 60-self.songImg.mh_width, 20)];
    self.sh_contactLb.font = FONT(14);
    self.sh_contactLb.textColor = themeTextColor;
//    self.sh_contactLb.backgroundColor = [UIColor redColor];
//    self.sh_contactLb.text = @"王二 先生 15123456789";
    [self addSubview:self.sh_contactLb];
    
    self.storeCallBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.storeCallBtn.frame = CGRectMake(SCREEN_WIDTH-55, 25, 40, 42);
    [self.storeCallBtn setImage:IMAGE(@"dianhua") forState:UIControlStateNormal];
    [self addSubview:self.storeCallBtn];
    
    
    self.contactCallBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.contactCallBtn.frame = CGRectMake(SCREEN_WIDTH-55, self.storeCallBtn.mh_bottom+50, 40, 42);
    [self.contactCallBtn setImage:IMAGE(@"dianhua") forState:UIControlStateNormal];
    [self addSubview:self.contactCallBtn];
    
    
    self.distanceLb = [[UILabel alloc] initWithFrame:CGRectMake(0, (GetHeight(self)-20)/2.0, 60, 20)];
    self.distanceLb.textAlignment = NSTextAlignmentCenter;
    self.distanceLb.font = FONT(14);
//    self.distanceLb.text = @"1.5km";
    [self addSubview:self.distanceLb];
    
    
    [QTTools tool_addLineWithFrame:CGRectMake(15+self.quImg.mh_width/2.0, self.quImg.mh_bottom+3, 1, (70-20)/2.0-3) superView:self];
    [QTTools tool_addLineWithFrame:CGRectMake(15+self.quImg.mh_width/2.0, self.distanceLb.mh_bottom, 1, (70-20)/2.0-3) superView:self];
    
}


-(void)setOrderModel:(OrderModel *)orderModel {
    self.qh_storeLb.text = orderModel.shop.name;
    self.qh_addressLb.text = orderModel.shop.address;
    self.sh_addressLb.text = [NSString stringWithFormat:@"%@%@", orderModel.user.region, orderModel.user.detail];
    self.sh_contactLb.text = [NSString stringWithFormat:@"%@ %@ %@", orderModel.user.consignee, [orderModel.user.sex isEqualToString:@"1"]?@"女士":@"先生", orderModel.user.phone];
    self.distanceLb.text = _orderModel.str3.length==0||_orderModel.str3==nil?@"计算中...":_orderModel.str3;
}

-(void)setOrderState:(OrderState)orderState{
    _orderState = orderState;
    CGFloat lableWidth = SCREEN_WIDTH -15-25-self.quImg.mh_width-self.storeCallBtn.width-15-10;
    if (self.orderState == ReceiveState) {///接单正常
        lableWidth = SCREEN_WIDTH - 60-self.songImg.mh_width;
        CGRect frame = self.sh_addressLb.frame;
        frame.size.height = 40;
        self.sh_addressLb.frame = frame;
        self.sh_contactLb.hidden = YES;
        self.storeCallBtn.hidden = YES;
        self.contactCallBtn.hidden = YES;
    }else if (self.orderState == GetFoodState){///待取餐
        CGRect frame = self.sh_addressLb.frame;
        frame.size.height = 25;
        self.sh_addressLb.frame = frame;
        self.sh_contactLb.hidden = NO;
        self.storeCallBtn.hidden = NO;
        self.contactCallBtn.hidden = NO;
    }else if (self.orderState == SendState){///配送
        CGRect frame = self.sh_addressLb.frame;
        frame.size.height = 25;
        self.sh_addressLb.frame = frame;
        self.sh_contactLb.hidden = NO;
        self.storeCallBtn.hidden = NO;
        self.contactCallBtn.hidden = NO;
    }
    
    self.qh_storeLb.frame = CGRectMake(self.quImg.mh_right+25, self.quImg.mh_top-5, lableWidth, 25);
    self.sh_contactLb.frame = CGRectMake(self.sh_addressLb.mh_left, self.sh_addressLb.mh_bottom, lableWidth, 20);
    self.sh_addressLb.frame = CGRectMake(self.songImg.mh_right+25, self.songImg.mh_top-5, lableWidth, 25);
    self.qh_addressLb.frame = CGRectMake(self.qh_storeLb.mh_left, self.qh_storeLb.mh_bottom, lableWidth, 20);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
